package cn.wzptsoft.mall.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.wzptsoft.mall.pojo.Theme;
import cn.wzptsoft.mall.pojo.result.Result;
import cn.wzptsoft.mall.pojo.vo.ThemeVo;
import cn.wzptsoft.mall.service.IThemeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/theme")
@Slf4j
@Tag(name = "专题相关接口")
@RequiredArgsConstructor
public class ThemeController {

    private final IThemeService iThemeService;

    @GetMapping("by/names")
    @Operation(summary = "查询专题信息")
    public Result<List<ThemeVo>> getTheme(String arr) {
        List<String> list = Arrays.asList(arr.split(","));

        List<ThemeVo> res = iThemeService.listByNames(list);
        return Result.ok(res);
    }

    @GetMapping
    @Operation(summary = "查询所有专题")
    public Result<List<ThemeVo>> list(){
        List<Theme> list = iThemeService.list();
        List<ThemeVo> vos = list.stream().map(item -> BeanUtil.copyProperties(item, ThemeVo.class)).toList();
        return Result.ok(vos);

    }

}
